<template>
  <div class="product">
    <!--添加消息模板-->
    <div class="common-level-rail">
      <el-button type="primary" @click="addClick">新規</el-button>
    </div>

    <!--内容-->
    <div class="product-content">
      <div class="table-wrap">
        <el-table
          size="small"
          :data="tableData"
          border
          default-expand-all
          :tree-props="{ children: 'children' }"
          row-key="plus_id"
          v-loading="loading"
          empty-text="データがありません"
        >
          <el-table-column prop="numbers" label="請求書番号"></el-table-column>
          <el-table-column prop="client_name" label="取引先名"></el-table-column>
          <el-table-column prop="money" label="請求金額"></el-table-column>
          <el-table-column prop="file_name" label="件名"></el-table-column>
          <el-table-column prop="account_name" label="振込先"></el-table-column>
          <el-table-column prop="account_content" label="振込先口座"></el-table-column>
          <el-table-column prop="meno" label="備考"></el-table-column>
          <el-table-column prop="tags" label="タグ"></el-table-column>
          <el-table-column prop="create_time" label="作成日"></el-table-column>
          <el-table-column fixed="right" label="操作">
            <template #default="scope">
              <el-button @click="editClick(scope.row)" link type="primary" size="small"
                >編集</el-button
              >
              <el-button @click="deleteClick(scope.row)" link type="primary" size="small"
                >削除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import billApi from "@/api/bill.js";
import { deepClone } from "@/utils/base.js";
import router from "../../../router";
export default {
  data() {
    return {
      loading: true,
      /*切换选中值*/
      activeIndex: "0",
      /*横向表单数据模型*/
      formInline: {
        user: "",
        region: "",
      },
      /*表格数据*/
      tableData: [],
      /*总条数*/
      totalDataNumber: 0,
      /*分类列表*/
      categoryList: [],
      /*是否打开添加弹窗*/
      open_add: false,
      /*是否打开编辑弹窗*/
      open_edit: false,
      /*当前编辑的对象*/
      messageModel: {},
      /*是否打开字段弹窗*/
      open_field: false,
    };
  },
  created() {
    /*获取列表*/
    this.getTableList();
  },
  methods: {
    /*获取列表*/
    getTableList() {
      let self = this;
      let Params = {
        type: 1
      };
      billApi.lists(Params, true)
        .then((data) => {
          self.loading = false;
          self.tableData = data.data.list;
          self.totalDataNumber = data.data.list.total;
        })
        .catch((error) => {
          self.loading = false;
        });
    },
    /*打开添加*/
    addClick() {
      router.push('/bill/bill/Add');
    },
    /*打开编辑*/
    editClick(item) {
      router.push('/bill/bill/Edit?id=' + item.id);
    },
    closeDialogFunc(e, f) {
      if (f == "add") {
        this.open_add = e.openDialog;
        if (e.type == "success") {
          this.getTableList();
        }
      }
      if (f == "edit") {
        this.open_edit = e.openDialog;
        if (e.type == "success") {
          this.getTableList();
        }
      }
    },
    /*打开支行*/
    branchClick(item) {
      this.messageModel = item;
      this.open_field = true;
    },
    /*删除用户*/
    deleteClick(row) {
      let self = this;
      ElMessageBox.confirm("削除後の復元は不可能ですが、削除を確認しますか?", "ヒントです", {
        confirmButtonText: "確定",
        cancelButtonText: "キャンセル",
        type: "warning",
      })
        .then(() => {
          self.loading = true;
          billApi.deletes(
            {
              id: row.id,
            },
            true
          )
            .then((data) => {
              self.loading = false;
              ElMessage({
                message: data.msg,
                type: "success",
              });
              self.getTableList();
            })
            .catch((error) => {
              self.loading = false;
            });
        })
        .catch(() => {});
    },
  },
};
</script>

<style></style>
